package doujian.filter;

import doujian.filter.condition.Culture;
import doujian.filter.condition.Food;
import doujian.filter.condition.Hobby;
import doujian.filter.rules.Room;
import doujian.filter.rules.Sex;
import doujian.filter.rules.Location;
import doujian.model.Host;
import doujian.model.Student;
import doujian.util.Log;

import java.util.ArrayList;
import java.util.List;

/**
 * 条件筛选入口 Created by Administrator on 2017/4/16.
 */
public class Filter {

	/**
	 * 对特定的学生，获取可用的房东
	 *
	 * @param student
	 *            当前学生
	 * @param hostList
	 *            所有房东的列表
	 * @return
	 */
	public static List<Integer> getHostList(Student student, List<Host> hostList) {
		List<Integer> result = new ArrayList<Integer>();
		for (Host host : hostList) {
			if (Filter.filter(student, host)) {
				result.add(host.id);
			}
		}
		return result;
	}

	/**
	 * 对特定的学生，获取可用的房东
	 *
	 * @param host
	 *            当前房东
	 * @param stuList
	 *            所有学生的列表
	 * @return
	 */
	public static List<Integer> getStuList(Host host, List<Student> stuList) {
		List<Integer> result = new ArrayList<Integer>();
		for (Student student : stuList) {
			if (Filter.filter(student, host)) {
				result.add(student.id);
			}
		}
		return result;
	}

	/**
	 * 筛选算法 对房东和家庭做匹配
	 *
	 * @param student
	 *            特定学生
	 * @param host
	 *            特定房东
	 * @return
	 */
	private static boolean filter(Student student, Host host) {
		Log.d("Filter Start: " + "Student=" + student.id + ", Host=" + host.id);
		boolean rules = Room.filter(student, host) && Location.filter(student, host) && Sex.filter(student, host);
		// 目前的软性条件永远为true。等以后房源多了，需要的时候，再做处理。
		// double condition = Culture.filter(student,host) +
		// Food.filter(student,host) + Hobby.filter(student,host);
		return rules;
	}
}
